require([],function(){
    var URLS = {
        signIn : {
            url: '/user/commit/signIn',
            method: 'POST',
            type:'json',
        },
        signUp : {
            url: '/user/commit/signUp',
            method: 'POST',
            type:'json',
        }
    }
    function sloganAnimate (storyId){
        var $text = $('.slogan-text');
        var word = $text.html();
        $text.html('');
        //console.log(word);
        var length = word.length;
        for(var i in word){
            var item = word[i];
            setTimeout((function(w){
                //console.log(w);
                return function(){
                    $text.append("<span class='animated fadeInRight' >" + w + "</span>");
                }
            })(item), i * 1000 / 2);
            
        }

    }
    sloganAnimate();

    $("body").on("focus", ".input-email", function(){
        console.log(1);
        $(".login-hidden-wrap").addClass("animated fadeIn").removeClass("no-display");

    });
   
    //main
    var vueMainData = {
        email:'',
        password:'',
        isLogin: false,
        isHoverRegisterBtn: false,
        userInfo: _.clone(PageData.userInfo),
    };

    if(vueMainData.userInfo.user_id){
        vueMainData.isLogin = true;
    }
    var vm = new Vue({
        el: "#main",
        data: vueMainData,
        methods:{
            newStory: function(){
                location.href="/story/editStory";
            },
            readStory: function(){
                location.href="/story/";
            },
            history: function(){
                location.href="/chapter/readHistoryChapter";
            },
            logout: function(){
                location.href="/logout";
            },
            hoverSignInBtn: function(){},
            hoverRegisterBtn: function(){
                console.log('hover');
                vueMainData.isHoverRegisterBtn = true;
                return false;
            },
            submitLoginForm: function(){


                var formData = {
                    email: vueMainData.email,
                    password: vueMainData.password,
                };
                $.ajax({
                    type: URLS.signIn.method,
                    dataType: URLS.signIn.type,
                    url:  URLS.signIn.url,
                    data: formData,
                    success: function (result) {
                        if(0 == result.errno){
                            location.reload();
                        } else {
                            alert(result.errmsg);
                        }
                    },
                    error: function(data) {
                        console.log("ajax faild");
                    }
                });
                return false;
            },
            signUpForm: function() {
                var tip = "邮箱:" + vueMainData.email + " 密码:" + vueMainData.password;
                var ret  = confirm(tip);
                if(ret){
                    var formData = {
                        email: vueMainData.email,
                        password: vueMainData.password,
                    };
                    $.ajax({
                        type: URLS.signUp.method,
                        dataType: URLS.signUp.type,
                        url:  URLS.signUp.url,
                        data: formData,
                        success: function (result) {
                            if(0 == result.errno){
                                alert(result.errmsg);
                            } else {
                                alert("注册失败");
                            }
                        },
                        error: function(data) {
                            console.log("ajax faild");
                        }
                    });
                }
                
            },
        }
    });
   
});